﻿

function getRef(name)
{
	return document.all ? document.all[name] : document.getElementById(name);
}

function checkAvailability(objTxt,objNo,curr,prod_id)
{
	 
	var AgntUsr=navigator.userAgent.toLowerCase();
	var AppVer=navigator.appVersion.toLowerCase();
	
	var NavYes=AgntUsr.indexOf('mozilla')!=-1&&AgntUsr.indexOf('compatible')==-1?1:0;
	var ExpYes=AgntUsr.indexOf('msie')!=-1?1:0;
	var Opr=AgntUsr.indexOf('opera')!=-1?1:0;
	
 if(!ExpYes)
 {
	 				
	 if(parseInt(objNo)>0 || objNo!="")
	 {
		 
		for( i=0 ; i<objNo; i++)	
		{
			var strCode='code['+i+']';
			
			var strCodeName=document.getElementsByName(strCode);
			
			for (var j = 0; j < strCodeName.length; j++) 
			{  
				
				if(curr.name!=strCodeName[j].name)
				{
					if(objTxt==strCodeName[j].value)
					{
						alert("Please enter unique product code");
					}
					/*else if(strCodeName[j].value!="" && strCodeName[j].value.length!=10)
					{
						alert("Unique product code can not be less than 10 digit");
					}*/
				}
				/*else if(curr.value!="" && curr.value.length!=10)
				{
					alert("Unique product code can not be less than 10 digit");
				}*/				
			}
		}	  
	 }
 }
 	
if(ExpYes)
{
 	var strCodeName = document.getElementsByName('code[0]');//here rr[] is the name of the textbox 
	 var flag=0;       
	 //alert(chks.length);
	for (var i = 0; i < strCodeName.length; i++) 
	 {  
	 	//alert(chks[i].value);
		if(curr.name!=strCodeName[i].name)
		{
			if(objTxt==strCodeName[i].value)
			{
				alert("Please enter unique product code");
			}
			else if(strCodeName[i].value!="" && strCodeName[i].value.length!=10)
			{
				alert("Unique product code can not be less than 10 digit");
			}
		}
		else if(curr.value!="" && curr.value.length!=10)
				{
					alert("Unique product code can not be less than 10 digit");
				}	
	 } 
}
	// alert(objTxt);
    var Code=objTxt;
	if(Code!="")
	{
	   createAjaxObj();
	   xmlindicator=(arguments.length>0)? 1 : 0;
	   var url = "CodeAvailability.php?Code=" + Code+"&prod_id="+prod_id;
	   xmlHttp.open("GET", url);
	   //curr.focus();
	   //getRef('DivAvailabilityResult').innerHTML ="Please Wait...";
	   xmlHttp.onreadystatechange = callBackCheckAvailability;
	   xmlHttp.send(null);
	}	
}


function callBackCheckAvailability()
{
	if(xmlHttp.readyState == 4) 
	{
		if(xmlHttp.status == 200) 
		{
			//getRef('DivAvailabilityResult').innerHTML =xmlHttp.responseText;
			if(xmlHttp.responseText!="")
				alert(xmlHttp.responseText);
		}
		else if(xmlHttp.status == 404) 
		{
			alert("Sorry, Resource Is Unavailable");
		}
		else 
		{
			//alert("Sorry, Unexpected Response Status: " + xmlHttp.status);
		}

	}
}
function add_Sold(objNo,objValues)
{
	
    var vRTEs = objValues.split(",");
	
	var strCode='msg['+0+']';
			
	var strCodeName=document.getElementsByName(strCode);
	
	for (var i = 0; i < strCodeName.length; i++) 
	{  
		if(vRTEs[i]!=undefined && vRTEs[i]==1)
		{
			strCodeName[i].innerHTML="Sold";
		}		
	 } 
	
			
    //for(var i=0;i<objNo;i++)
//	{
//		
//		if(vRTEs[i]!=undefined)
//		{
//			
//			//addRowValue(vRTEs[i+1]);			
//			
//			var strCode='msg['+i+']';
//			
//			var strCodeName=document.getElementsByName(strCode);
//			if(vRTEs[i]==1)
//			{
//				for (var j = 0; j < strCodeName.length; j++) 
//				 {  
//					if(i==j)
//					{
//						strCodeName[j].innerHTML="Sold";
//					}
//					
//				 }											
//			}	
//			
//		}
//		else
//		{
//			alert('bi');
//		   //addRow();
//		}
//	} 

}
 
function addRowsWithValue(objNo,objValues)
{
    
    var sub=checkRow();   
    var vRTEs = objValues.split(",");
	
    if(objNo>sub)
    {
		
        for(var i=0;i<objNo-sub;i++)
        {
			
            if(vRTEs[i+1]!=undefined)
            {
				//alert(vRTEs[i+1]);
                addRowValue(vRTEs[i+1]);
            }
            else
            {
               addRow();
            }
        }
    }    
}
function addRows(objNo)
{
	if(parseInt(objNo)>0)
	{
		var sub=checkRow();
		if(objNo>sub)
		{
			for(var i=0;i<objNo-sub;i++)
			{
				addRow();
			}
		}
		else if(objNo<sub)
		{
		   for(var j=sub;objNo<j;j--)
		   {
				RemoveRow(j-1);
		   }
		}
	}
	else
	{
		alert("Please enter valid no of quantity");
		this.focus();
	}
}
function checkRow()
{
    /* Declare variables */
    var elements, templateRow, rowCount, row, className, newRow, element;
    var i, s, t;
    
    /* Get and count all "tr" elements with class="row".    The last one will
     * be serve as a template. */
    if (!document.getElementsByTagName)
        return false; /* DOM not supported */
    elements = document.getElementsByTagName("div");
    templateRow = null;
    rowCount = 0;
    
    for (i = 0; i < elements.length; i++) {
        row = elements.item(i);
        
        /* Get the "class" attribute of the row. */
        className = null;
        if (row.getAttribute)
            className = row.getAttribute('class')
        if (className == null && row.attributes) {    // MSIE 5
            /* getAttribute('class') always returns null on MSIE 5, and
             * row.attributes doesn't work on Firefox 1.0.    Go figure. */
            className = row.attributes['class'];
            if (className && typeof(className) == 'object' && className.value) {
                // MSIE 6
                className = className.value;
            }
        } 
        
        /* This is not one of the rows we're looking for.    Move along. */
        if (className != "row_to_clone")
            continue;
        
        /* This *is* a row we're looking for. */
        templateRow = row;
        rowCount++;
    }
    return rowCount;
}
function addRow() {
    /* Declare variables */
    var elements, templateRow, rowCount, row, className, newRow, element;
    var i, s, t;
    
    /* Get and count all "tr" elements with class="row".    The last one will
     * be serve as a template. */
    if (!document.getElementsByTagName)
        return false; /* DOM not supported */
    elements = document.getElementsByTagName("div");
    templateRow = null;
    rowCount = 0;
    
    for (i = 0; i < elements.length; i++) {
        row = elements.item(i);
        
        /* Get the "class" attribute of the row. */
        className = null;
        if (row.getAttribute)
            className = row.getAttribute('class')
        if (className == null && row.attributes) {    // MSIE 5
            /* getAttribute('class') always returns null on MSIE 5, and
             * row.attributes doesn't work on Firefox 1.0.    Go figure. */
            className = row.attributes['class'];
            if (className && typeof(className) == 'object' && className.value) {
                // MSIE 6
                className = className.value;
            }
        } 
        
        /* This is not one of the rows we're looking for.    Move along. */
        if (className != "row_to_clone")
            continue;
        
        /* This *is* a row we're looking for. */
        templateRow = row;
        rowCount++;
    }
    if (templateRow == null)
        return false; /* Couldn't find a template row. */
    
    /* Make a copy of the template row */
    newRow = templateRow.cloneNode(true);

    /* Change the form variables e.g. price[x] -> price[rowCount] */
    elements = newRow.getElementsByTagName("input");
    for (i = 0; i < elements.length; i++) {
        element = elements.item(i);
        s = null;
        s = element.getAttribute("name");
        if (s == null)
            continue;
        t = s.split("[");
        if (t.length < 2)
            continue;
        s = t[0] + "[" + rowCount.toString() + "]";
        element.setAttribute("name", s);
        element.value = "";
    }
    
    /* Add the newly-created row to the table */
    templateRow.parentNode.appendChild(newRow);
    return true;
}
function RemoveRow(objID) {
    /* Declare variables */
	
    var elements, templateRow, rowCount, row, className, newRow, element;
    var i, s, t;
    
    /* Get and count all "tr" elements with class="row".    The last one will
     * be serve as a template. */
    if (!document.getElementsByTagName)
        return false; /* DOM not supported */
    elements = document.getElementsByTagName("div");
    templateRow = null;
    rowCount = 0;
    
    for (i = 0; i < elements.length; i++) {
        row = elements.item(i);
        
        /* Get the "class" attribute of the row. */
        className = null;
        if (row.getAttribute)
            className = row.getAttribute('class')
        if (className == null && row.attributes) {    // MSIE 5
            /* getAttribute('class') always returns null on MSIE 5, and
             * row.attributes doesn't work on Firefox 1.0.    Go figure. */
            className = row.attributes['class'];
            if (className && typeof(className) == 'object' && className.value) {
                // MSIE 6
                className = className.value;
            }
			
        } 
        
        /* This is not one of the rows we're looking for.    Move along. */
        if (className != "row_to_clone")
            continue;
        
        /* This *is* a row we're looking for. */
        templateRow = row;
        rowCount++;
    }
    if (templateRow == null)
        return false; /* Couldn't find a template row. */
		
    templateRow.parentNode.removeChild(templateRow);
    /* Make a copy of the template row */    
    return true;
}

function addRowValue(objVal) {
    /* Declare variables */
    var elements, templateRow, rowCount, row, className, newRow, element;
    var i, s, t;
    
    /* Get and count all "tr" elements with class="row".    The last one will
     * be serve as a template. */
    if (!document.getElementsByTagName)
        return false; /* DOM not supported */
    elements = document.getElementsByTagName("div");
    templateRow = null;
    rowCount = 0;
    
    for (i = 0; i < elements.length; i++) {
        row = elements.item(i);
        
        /* Get the "class" attribute of the row. */
        className = null;
        if (row.getAttribute)
            className = row.getAttribute('class')
        if (className == null && row.attributes) {    // MSIE 5
            /* getAttribute('class') always returns null on MSIE 5, and
             * row.attributes doesn't work on Firefox 1.0.    Go figure. */
            className = row.attributes['class'];
            if (className && typeof(className) == 'object' && className.value) {
                // MSIE 6
                className = className.value;
            }
        } 
        
        /* This is not one of the rows we're looking for.    Move along. */
        if (className != "row_to_clone")
            continue;
        
        /* This *is* a row we're looking for. */
        templateRow = row;
        rowCount++;
    }
    if (templateRow == null)
        return false; /* Couldn't find a template row. */
    
    /* Make a copy of the template row */
    newRow = templateRow.cloneNode(true);

    /* Change the form variables e.g. price[x] -> price[rowCount] */
    elements = newRow.getElementsByTagName("input");
    for (i = 0; i < elements.length; i++) {
        element = elements.item(i);
        s = null;
        s = element.getAttribute("name");
        if (s == null)
            continue;
        t = s.split("[");
        if (t.length < 2)
            continue;
        s = t[0] + "[" + rowCount.toString() + "]";
        element.setAttribute("name", s);
        element.value =objVal;
    }
    
    /* Add the newly-created row to the table */
    templateRow.parentNode.appendChild(newRow);
    return true;
}
/* set ts=8 sw=4 sts=4 expandtab: */
